package com.guoranhao.web.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Description: 公共参数拦截器 Copyright (c) Department of Research and
 * Development/Beijing All Rights Reserved.
 * @version 1.0 2016年9月1日 下午7:22:32 by 陆怀彬（luhb@cloud-young.com）陆怀彬
 */
@Component
public class ParameterInterceptor extends HandlerInterceptorAdapter {
	private static final Logger logger = LoggerFactory.getLogger(ParameterInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
//		UserLoginBindingParameter binding = new UserLoginBindingParameter();
//		if(StringUtils.isEmpty(request.getHeader(ApiConstants.PLATFORM_NO))){
//			binding.setPlatformNo(ApiConstants.UNKNOWN);
//		}else{
//			binding.setPlatformNo(request.getHeader(ApiConstants.PLATFORM_NO));
//		}
//		if(StringUtils.isEmpty(request.getHeader(ApiConstants.VERSION))){
//			binding.setVersion(ApiConstants.UNKNOWN);
//		}else{
//			binding.setVersion(request.getHeader(ApiConstants.VERSION));
//		}
//		if(StringUtils.isEmpty(request.getHeader(ApiConstants.DEVICEMODEL))){
//			binding.setDeviceModel(ApiConstants.UNKNOWN);
//		}else{
//			binding.setDeviceModel(request.getHeader(ApiConstants.DEVICEMODEL));
//		}
//		if(StringUtils.isEmpty(request.getHeader(ApiConstants.DEVICETYPE))){
//			binding.setDeviceType(ApiConstants.UNKNOWN);
//		}else{
//			binding.setDeviceType(request.getHeader(ApiConstants.DEVICETYPE));
//		}
//		if(StringUtils.isEmpty(request.getHeader(ApiConstants.IMSI))){
//			binding.setDeviceImsi(ApiConstants.UNKNOWN);
//		}else{
//			binding.setDeviceImsi(request.getHeader(ApiConstants.IMSI));
//		}
//		if(StringUtils.isEmpty(request.getHeader(ApiConstants.IMEI))){
//			binding.setDeviceImei(ApiConstants.UNKNOWN);
//		}else{
//			binding.setDeviceImei(request.getHeader(ApiConstants.IMEI));
//		}
//		if(StringUtils.isEmpty(request.getHeader(ApiConstants.APP_CLIENT))){
//			binding.setAppClient(ApiConstants.UNKNOWN);
//		}else{
//			binding.setAppClient(request.getHeader(ApiConstants.APP_CLIENT));
//		}
//		if(StringUtils.isBlank(request.getHeader(ApiConstants.DEVICEBRAND))){
//			binding.setDeviceBrand(ApiConstants.UNKNOWN);
//		}else{
//			binding.setDeviceBrand(request.getHeader(ApiConstants.DEVICEBRAND));
//		}
//		String accessChannel = request.getHeader(ApiConstants.ACCESS_CHANNEL);
//		if(StringUtils.isEmpty(accessChannel)){
//			binding.setAccessChannel(ApiConstants.UNKNOWN);
//		}else{
//			binding.setAccessChannel(accessChannel);
//		}
//
//		if(!StringUtils.isEmpty(request.getHeader(ApiConstants.LONGITUDE)) &&
//				!StringUtils.isEmpty(request.getHeader(ApiConstants.LATITUDE))){
//			binding.setLongitude(Double.valueOf(request.getHeader(ApiConstants.LONGITUDE)));
//			binding.setLatitude(Double.valueOf(request.getHeader(ApiConstants.LATITUDE)));
//		}
//
//		if(!StringUtil.isEmpty(request.getHeader(ApiConstants.APP_VERSION_CODE))){
//			binding.setAppVersionCode(Integer.valueOf(request.getHeader(ApiConstants.APP_VERSION_CODE)));
//		}
//		binding.setLastLoginIp(IpUtil.getRealIp(request));
//		request.setAttribute(ApiConstants.LOGIN_BINDING, binding);
		return true;
	}

}
